<?php use_javascript('jquery-1.3.2.min.js') ?>
<?php use_helper ('Form','Javascript','Object') ?>

<?php use_javascript('prototype.js') ?>		
<?php use_javascript('effects.js') ?>		
<?php use_javascript('dragdrop.js') ?>		
<?php use_javascript('popup.js') ?>		
<link href="<?php echo _compute_public_path('popup', 'css', 'css', false);  ?>" rel="stylesheet" type="text/css" />	

<table width="100%" border="0" cellspacing="0" cellpadding="0"  class="heading_table">
    <tr>
        <td height="30"><span class="heading">Buildings at Stations</span></td>
        <td align="right" height="30" valign="bottom">
        <span style="float:right"><?php echo image_tag('icon_addRight.jpg', 'width="2"', 'height="22"')?></span>
        <a class="addNew" id="popup_link_add" href="#">Add New Building</a>
        </td>
    </tr>
    
</table> 
 

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="datagrid">
             
    <tr>
        <th width="8%" style="text-align:left;">Station</th>
        <th width="23%" style="text-align:left;">Building Name</th>
        <th width="17%" style="text-align:left;">Consumer No.</th>
        <th width="14%" style="text-align:left;">Meter No.</th>
        <th width="17%" style="text-align:left;">Meter Phase</th>
       <!--<th width="8%" style="text-align:left;">Status</th>-->
        <th width="13%" style="text-align:left;">Last Updated</th>
        <th width="8%" style="text-align:left;">Operation</th>
    </tr>

<!-- Populating the List -->
<?php if (count($buildings)): ?>
    <?php $previous = "";?>
	<?php foreach ($buildings as $j => $building) : ?>
    <?php $current = $building->getStation(); ?>
        <?php if ($current != $previous): ?>
        <tr>
            <td colspan="7" class="subhdng">
            <strong><?php echo $current ;?></strong>
            </td>
        </tr>
    <?php endif; ?>

    <tr>
        <td align="left">&nbsp;<?php //echo $building->getStation(); ?></td>
        <td align="left"><?php echo $building->getBuildingNo(); ?> </td>
        <td align="left"><?php echo $building->getConsumerNo(); ?></td>
        <td align="left"><?php echo $building->getMeterNo(); ?></td>
        <td align="left">&nbsp;<?php echo $building->getMeterPhase(); ?></td>
        <!--<td align="center"><?php //echo Constant::GetRecordStatusTitle($building->getStatus()); ?></td>-->
        <td align="center"><?php echo $building->getUpdatedAt('d-M-Y'); ?>
        <td align="right" class="edit">
        <?php echo link_to('&nbsp;','Building/edit?id='.Utility::EncryptQueryString($building->getId()),array('title'=>'Edit', 'class' => 'edit'))?>
        <?php echo link_to('&nbsp;','Building/delete?id='.Utility::EncryptQueryString($building->getId()), array('confirm'=>'Are you sure you want to Delete this?', 'title'=>'Delete', 'class' => 'delete')); ?>
        </td>
    </tr>
<?php $previous = $current;?>
<?php endforeach; ?>
    <tr>
   		<td class="last">&nbsp;</td>
    </tr>
<?php else:?>

<tr>
	<td colspan="6" style="background:none; text-align:center;"><?php echo Constant::RECORD_NOT_FOUND; ?></td>
</tr>

<?php endif; ?>
</table>

<div id="popup_add" class="popup" style="width:600px" >
<?php echo form_tag('Building/add') ?>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td style="padding-left:10px" height="30"><span class="heading">Add New Building at Station</span></td>
    <td align="right" style="padding-right:10px"><a class="popup_closebox" href="#"><?php echo image_tag('btn_x.gif', 'border=0'); ?></a></td>
  </tr>
</table>

<table width="100%" align="left"  border="0"  cellpadding="0" cellspacing="0" class="form" bgcolor="#eeeeee">
  
  <tr>
  	<td align="left" height="30" style="padding-left:10px; padding-top:10px">Station:</td>
	<td height="30" style="padding-left:10px;"> <?php echo object_select_tag('', '', array ( 'name'=>'station_id', 'id'=>'station_id', 'related_class' => 'Station' , 'peer_method' => 'GetStation'));?> </td>
</tr>
  
  <tr>
    <td width="148" height="30" style="padding-left:10px;">Building Name:<span class="error"> *</span></td>
	<td width="452" height="30" style="padding-left:10px;"> <?php echo input_tag('building_no','','size=38') ?></td>
	<script type="text/javascript">
	var building_no = new LiveValidation('building_no', { validMessage: "<?php echo Constant::VALIDATION_SUCCESS; ?>"});
	building_no.add( Validate.Presence,{ failureMessage: "<?php echo Constant::VALIDATION_REQUIRED_FIELD; ?>"});
	</script>
  </tr>
 
  <tr>
    <td width="148" height="30" style="padding-left:10px;">Consumer No. :</td>
	<td width="452" height="30" style="padding-left:10px;"> <?php echo input_tag('consumer_no','','size=38') ?></td>
  </tr>
 
 <tr>
    <td width="148" height="30" style="padding-left:10px;">Meter No. :<span class="error"> *</span></td>
	<td width="452" height="30" style="padding-left:10px;"> <?php echo input_tag('meter_no','','size=38') ?></td>
	<script type="text/javascript">
	var meter_no = new LiveValidation('meter_no', { validMessage: "<?php echo Constant::VALIDATION_SUCCESS; ?>"});
	meter_no.add( Validate.Presence,{ failureMessage: "<?php echo Constant::VALIDATION_REQUIRED_FIELD; ?>"});
	</script>
  </tr>
  
  <tr>
    <td width="148" height="30" style="padding-left:10px;">Meter Phase:<span class="error"> *</span></td>
	<td width="452" height="30" style="padding-left:10px;">
    <?php echo radiobutton_tag('meter_phase[]', Constant::SINGLE_PHASE_METER, true, array('class'=>'checkbox')) ?>1 Phase &nbsp;&nbsp;&nbsp;
	<?php echo radiobutton_tag('meter_phase[]', Constant::THREE_PHASE_METER, false, array('class'=>'checkbox')) ?>3 Phase
    </td>
  </tr>
 
  <tr>
    <td>&nbsp;</td>
  </tr>
 
  <tr>
    <td>&nbsp;</td>
    <td colspan="2">
    <table width="100%" align="left"  border="0" class="form">
        <tr>
            <td width="2%"><?php echo submit_tag('', array('class'=>'btn_add', 'style'=>'border:none')); ?> </td>
            <td width="98%"><a class="popup_closebox" href="#"><?php echo image_tag('btn_cancel.gif', 'border=0') ;?></a></td>
        </tr>
    </table>
    </td>
  </tr>
</table>
</div>

</div>
<script type="text/javascript">
    //<![CDATA[
    new Popup('popup_add','popup_link_add',{modal:true,duration:1})
    //]]>
  </script>